package lz.controls.nickScroll
{
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	
	import lz.controls.LScrollBar;
	import lz.controls.events.ScrollEvent;

	/**
	 * 横向滚动条 --滚动条 
	 * @author Administrator
	 * 
	 */	
	public class HScrollBarWithBar extends Sprite
	{
		private var _scrollBar:LScrollBar;
		
		/**
		 *容器 
		 */
		private var _contain:Sprite;
		/**
		 *目标容器 
		 */
		private var _target:Sprite;
		/**
		 *内容高度 
		 */
		private var _targetHeight:int;
		public function HScrollBarWithBar()
		{
			super();
		}
		/**
		 * 设置大小 
		 * @param $width
		 * @param $height
		 * 
		 */
		public function setSize($width:int,$height:int,$style:String = null):void
		{
			if(_scrollBar != null)return;
			_scrollBar = new LScrollBar();
			if($style != null)
				_scrollBar.skin = $style;
			_contain = new Sprite();
			this.addChild(_scrollBar);
			this.addChild(_contain);
//			_scrollBar.x = $height + 2;
			_scrollBar.height = $width;
			_scrollBar.rotation = -90;
			_scrollBar.y = $height;
			_contain.scrollRect = new Rectangle(0,0,$width,$height);
			_scrollBar.addEventListener(ScrollEvent.SCROLL,onHandler,false,0,true);
		}
		protected function onHandler(event:ScrollEvent):void
		{
			//trace("_target"+_target.height);
			_target.x = -(_targetHeight -_scrollBar.height) * (event.position /_scrollBar.maxScrollPosition );
//			trace(_target.x);
		}
		/**
		 * 设置目标容器 
		 * @param $target
		 * 
		 */
		public function set target($target:Sprite):void
		{
			_target = $target;
			_contain.addChild(_target);
//			if(_target.height <= _scrollBar.height)_scrollBar.alpha = 0;
		}
		/**
		 *内容容器高度 
		 * @param $value
		 * 
		 */
		public function set targetHeight($value:int):void
		{
			_targetHeight = $value;
		}
		public function get targetHeight():int
		{
			return _targetHeight;
		}
	}
}